<?php

namespace app\libs\redis;

use yii\di\Instance;
use yii\redis\connection;

class ARedisList
{
    public $redis = 'redis';

    public function __construct()
    {
        $this->redis = Instance::ensure($this->redis, Connection::className());
    }
    public function add($name = '', $item)
    {
        $res = $this->redis->executeCommand('RPUSH', ['myList', 'fefefe484']);
        $res = $this->redis->executeCommand('RPUSH', ['myList', 'fefefe598']);
        $res = $this->redis->executeCommand('RPUSH', ['myList', 'fefefe261']);
//        $v   = $this->redis->executeCommand('RPOP', ['myList']);
        //        var_dump($res, $v);die;
        die;
        if (empty($name)) {
            throw new CException(get_class($this) . ' requires a name!');
        }
        if (!$this->redis->executeCommand('RPUSH', [$name, $item])) {
            return false;
        }
        return true;
    }
    public function get($name)
    {
        $res = $this->redis->executeCommand('RPOP', [$name]);
    }
    public function push($name = '', $item)
    {
        $this->add($name, $item);
    }
    public function exists($key)
    {
        return (bool) $this->redis->executeCommand('EXISTS', [$this->buildKey($key)]);
    }
}
